﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Dukou.WebSiteDesigner.Domain;
using System.Threading;

namespace Dukou.WebSiteDesigner.Web.Controllers
{
    public class DesignerController : Controller
    {
        public IPageDesigner PageDesigner { get; set; }

        public ActionResult CreatePage(string paths)
        {
            if (this.Request.HttpMethod == "POST")
            {
                IList<Container> containers = Container.Parse(paths).Where(x => x.Path.IndexOf('.') < 0).ToList();

                Page page = new Page() 
                {
                    Title = "test",
                    Containers = new List<Container>()
                };
                foreach (var item in containers)
                {
                    item.Page = page;
                    page.Containers.Add(item);
                }
                this.PageDesigner.SaveOrUpdate(page);
            }

            

            return View();
        }

        public ActionResult get_page(Int64? id) 
        {
            Thread.SetData(Thread.GetNamedDataSlot("DUKOU_PAGE_ID"), id.GetValueOrDefault());

            return View("get_page/" + id.GetValueOrDefault());
        }

        public ActionResult Test()
        {
            return View();
        }
    }
}
